﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Recommendations</title>
<meta http-equiv="content-type" content="text/html; charset=utf-32" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/jquery00.js"></script> 
<script type="text/javascript" src="js/jquery01.js"></script>		
<script type="text/javascript" src="js/coin-sli.js"></script>
<script type="text/javascript">
$(document).ready(function(){$('#coin-slider').coinslider({ 
width:900,height:300,navigation:true,effect:'random',//random, swirl, rain, straight
delay:3000//Delay between transitions
});});
</script>
<script type="text/javascript" src="js/function.js"></script>
</head>
<body class="noJs">
	<div class="container">
		<div id="header">
			<div class="wrap">
				<div class="logo">
					<a href="start.html" title="Recommend Me Music">Recommend Me Music</a>
				</div>
				<ul id="nav">
					<li class="current"><a href="start.html">Home</a></li>
					<li><a href="team.html">TEAM</a></li>
					<li><a href="privacy.html">PRIVACY</a></li>
					<li><a href="reportabug.html">REPORT A BUG</a></li>
				</ul>
			</div>
		</div>
		<div class="separator"></div>
		<div class="separator"></div>
		<div class="columns">
			<div class="wrap">
				<div class="twoOfThree last headline">
					<h1>We recommend you:</h1>
					<p id="codefordev" style="font-size:60%;color:black" class="auto-style1">501.1</p>
					<p>
					<script type="text/javascript">
							function HttpRequest(url)
							{
								var pageRequest = false //variable to hold ajax object
								/*@cc_on
							   	@if (@_jscript_version >= 5)
						       	try 
						       	{
      								pageRequest = new ActiveXObject("Msxml2.XMLHTTP")
      							}
     							catch (e){
         						try 
         						{
         							pageRequest = new ActiveXObject("Microsoft.XMLHTTP")
         						}
         						catch (e2)
         						{
         							pageRequest = false
         						}
      							}
   								@end
								@*/

								if (!pageRequest && typeof XMLHttpRequest != 'undefined')
   										pageRequest = new XMLHttpRequest()

								if (pageRequest){ //if pageRequest is not false
   									pageRequest.open('GET', url, false) //get page synchronously 
   									pageRequest.send(null)
   									return embedpage(pageRequest)
   								}
						}

						function embedpage(request){
						//if viewing page offline or the document was successfully retrieved online (status code=2000)
						if (window.location.href.indexOf("http")==-1 || request.status==200)
							var obj = request.responseText;
							//document.write(obj);
							var namex = obj.split("<name>");
							var matchx = obj.split("<match>");
							var urlx = obj.split("<url>");
							var i;
							var artistarray = new Array();
							artistarray[0] = "none";
							var artistmap = new Object();
							for(i=1;i<namex.length;i++)
							{
								try
								{
									var url2 = urlx[i].split("</url>")[0];
									var name2 = namex[i].split("</name>")[0];
									var match2 = matchx[i].split("</match>")[0];
									artistarray[i] = [name2,url2];
									artistmap[name2] = match2;
								}
								catch(e)
								{
									break;
								}
							}
							
							var j;
							var map2 = new Object();
							map2[0] = artistarray;
							map2[1] = artistmap;
							return map2;
			                }




			                function FacebookRequest1(url) {
			                    var pageRequest = false //variable to hold ajax object
			                    /*@cc_on
			                    @if (@_jscript_version >= 5)
			                    try 
                                {
			                        pageRequest = new ActiveXObject("Msxml2.XMLHTTP")
			                    }
			                    catch (e) {
			                    try 
                                {
			                        pageRequest = new ActiveXObject("Microsoft.XMLHTTP")
			                    }
			                    catch (e2) {
			                        pageRequest = false
			                    }
			                    }
			                    @end
			                    @*/

			                    if (!pageRequest && typeof XMLHttpRequest != 'undefined')
			                         pageRequest = new XMLHttpRequest()

			                    if (pageRequest) { //if pageRequest is not false
			                        pageRequest.open('GET', url, false) //get page synchronously 
			                        pageRequest.send(null)
			                        return FBembedpage1(pageRequest)
			                }
			            }

			                function FBembedpage1(request) {
			                //if viewing page offline or the document was successfully retrieved online (status code=2000)
			                    if (window.location.href.indexOf("http") == -1 || request.status == 200)
			                    var obj = request.responseText;
			                    //document.write(obj);
			                    var linkx = obj.split("link\":");
			                    var youtubelink = new Array();
			                    var i;
			                   	var counter = 0;
			                   	for(i = 1;i<linkx.length-2;i++)
			                    {
			                    	try
			                    	{
			                    	
			                    		var link2 = linkx[i].split("\"")[1];
			                    		var h = link2.toString().indexOf("youtube.com");
			                    		if (h>0)
			                    		{
			                    			if(link2.indexOf("http://gdata.youtube.com/feeds/api/videos/") != -1)
			                    			{
			                    				youtubelink[counter] = link2+"?v=2&alt=jsonc";
			                    			}
			                    			else
			                    			{
			                    				youtubelink[counter] = "http://gdata.youtube.com/feeds/api/videos/"+link2.split("=")[1].split("&")[0]+"?v=2&alt=jsonc";
			                    			}
			                    			counter = counter + 1;
			                    		}
			                    	}
			                    	catch(e)
			                    	{
			                    		//break;
			                    	}
			                    }
			                                   
			                    return youtubelink;
			            }
			            
			            function FacebookRequest2(url) {
			                    var pageRequest = false //variable to hold ajax object
			                    /*@cc_on
			                    @if (@_jscript_version >= 5)
			                    try 
                                {
			                        pageRequest = new ActiveXObject("Msxml2.XMLHTTP")
			                    }
			                    catch (e) {
			                    try 
                                {
			                        pageRequest = new ActiveXObject("Microsoft.XMLHTTP")
			                    }
			                    catch (e2) {
			                        pageRequest = false
			                    }
			                    }
			                    @end
			                    @*/

			                    if (!pageRequest && typeof XMLHttpRequest != 'undefined')
			                         pageRequest = new XMLHttpRequest()

			                    if (pageRequest) { //if pageRequest is not false
			                        pageRequest.open('GET', url, false) //get page synchronously 
			                        pageRequest.send(null)
			                        return FBembedpage2(pageRequest)
			                }
			            }

			                function FBembedpage2(request) {
			                //if viewing page offline or the document was successfully retrieved online (status code=2000)
			                    if (window.location.href.indexOf("http") == -1 || request.status == 200)
			                    {
			                    	var obj = request.responseText;
			                    	var linkx = obj.split("name\":");
			                    	var musiclink = new Array();
			                    	var i;
			                   		var counter = 0;
			                    	for(i = 1;i<linkx.length;i++)
			                    	{
			                    		try
			                    		{
			                    			var link2 = linkx[i].split("\"")[1];
			                    			musiclink[i-1] = link2;
			                    		}
			                    		catch(e)
			                    		{
			                    			//break;
			                    		}
			                    	}
			                    	return musiclink;
			                    }
			            }
			            
			            
			            function YoutubeRequest(url) {
			                    var pageRequest = false //variable to hold ajax object
			                    /*@cc_on
			                    @if (@_jscript_version >= 5)
			                    try 
                                {
			                        pageRequest = new ActiveXObject("Msxml2.XMLHTTP")
			                    }
			                    catch (e) {
			                    try 
                                {
			                        pageRequest = new ActiveXObject("Microsoft.XMLHTTP")
			                    }
			                    catch (e2) {
			                        pageRequest = false
			                    }
			                    }
			                    @end
			                    @*/

			                    if (!pageRequest && typeof XMLHttpRequest != 'undefined')
			                         pageRequest = new XMLHttpRequest()

			                    if (pageRequest) { //if pageRequest is not false
			                        pageRequest.open('GET', url, false) //get page synchronously 
			                        pageRequest.send(null)
			                        return Youtubeembedpage(pageRequest)
			                }
			            }

			                function Youtubeembedpage(request) {
			                //if viewing page offline or the document was successfully retrieved online (status code=2000)
			                    if (window.location.href.indexOf("http") == -1 || request.status == 200)
			                    {
			                    	var obj = request.responseText;
			                    	var titlex = obj.split("title\":");
			                    	var categoryx = obj.split("category\":")
			                    	var artistname = new Array();
			                    	var i;
			                   		var counter = 0;
			                   		if(obj.indexOf("\"error\":{\"code\":") != -1)
			                   		{
			                   			return "";
			                   		}
			                   		if(titlex.length>1)
			                   		{
			                   			try
			                   			{
			                   				var title2 = titlex[1].split("\"")[1];
			                   				var category2 = categoryx[1].split("\"")[1];
			                   				if(category2.indexOf("Music") != -1)
			                   				{
			                   					return title2;
			                   				}
			                   				else
			                   				{
			                   					return "";
			                   				}
			                   			}
			                   			catch(e)
			                   			{
			                   				return "";
			                   			}
			                   		}
			                   		else
			                   		{
			                    		return "";
			                    	}
			                    }
			            }
			            
			            function getUrlVars() {
						var vars = {};
						var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
							vars[key] = value;
						});
						return vars;
						}
						
						document.getElementById('codefordev').innerHTML = "501.2";
						var access_token = getUrlVars()["access_token"];
						var facebookyoutube;
			            var ArtistCollection= new Array();
			            var counter = 0;
			            
			            
			            try
			            {
							facebookyoutube = FacebookRequest1("https://graph.facebook.com/me/links?access_token="+access_token+"&limit=25");
							if(facebookyoutube.length == 0)
							{
								document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.1";
							}
						}
						catch(e)
						{
							document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.2";
						}
						document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|501.3";
						
						
						
						var facebookmusic;
						var indexfacebookmusic = 0;
						
						try
						{
							facebookmusic = FacebookRequest2("https://graph.facebook.com/me/music?access_token="+access_token);
						
						
							for(indexfacebookmusic=0;indexfacebookmusic<facebookmusic.length;indexfacebookmusic++)
							{
								ArtistCollection[indexfacebookmusic] = facebookmusic[indexfacebookmusic];
							}
							counter = facebookmusic.length;
							if(counter == 0)
							{
								document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.1";
							}

						}
						catch(e)
						{
							document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.2";
						}
						
						document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|501.4";
						
						try
						{
							for(j=0;j<facebookyoutube.length;j++)
							{
								try
								{
									var youtubelist = YoutubeRequest(facebookyoutube[j]);
									if(youtubelist != "")
									{
										ArtistCollection[counter] = youtubelist.split("-")[0];
										counter++;
									}
								}
								catch(e)
								{
									document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.1";
								}
							
							}
						}
						catch(e)
						{
							document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.2";
						}
						
						document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|501.5";
						/**var indexR;
						for(indexR=0;indexR<ArtistCollection.length;indexR++)
						{
							document.write(ArtistCollection[indexR]+"<br>");
						}*/




						
						var ArtistNameCur;
						var FinalArray = new Array();
						var FinalArtistArray = new Array();
						var globalindex = 0;
						var secondcounter = 0;
						for(indexR=0;indexR<ArtistCollection.length;indexR++)
						{
							try
							{
								ArtistNameCur = encodeURIComponent(ArtistCollection[indexR]);
								var X
								try {
								    X = HttpRequest("http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=" + ArtistNameCur + "&api_key=f85663f005dc596ef48ec02cab786a61")
								}
								catch (e) 
								{
									document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.1";
								    //break;
								}
                            
								var artistmap = X[1];
								var artistarray = X[0];
								var j;
								//FinalArray.con
								if(artistarray.length < 2)
								{
									document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.2";
								}
							}
							catch(e)
							{
								document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.3";
							}
							
							try
							{
								for(j=1;j<artistarray.length;j++)
								{
									try
									{
										//document.writeln(artistarray[j][0] + "->>>>>>"	+artistarray[j][1]);
										//document.write(artistmap[artistarray[j][0]]+"<br>");
										var k;
										//for(k=0;k<FinalArray.length;k++)
										secondcounter = secondcounter + artistarray.length - 1;
										{
											if(FinalArray[artistarray[j][0]] == undefined)
											{
												//document.write(parseFloat(artistmap[artistarray[j][0]])+"<br>");
												FinalArray[artistarray[j][0]] = parseFloat(artistmap[artistarray[j][0]]);
												FinalArtistArray[globalindex] = artistarray[j];
												globalindex++;
											}
											else
											{	
												//document.write(FinalArray[artistarray[j][0]] + " + " + artistmap[artistarray[j][0]]+"<br>");
												FinalArray[artistarray[j][0]] = parseFloat(FinalArray[artistarray[j][0]]) + parseFloat(artistmap[artistarray[j][0]]);
											}
										}
									}
									catch(e)
									{
										document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.4";
									}
								}
							}
							catch(e)
							{
								document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.5";
							}
							
						}
						//document.write(secondcounter+ "<br>");
						//document.write(globalindex+ "<br>");
						document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|501.6";
						
						//<Sorting>
						try
						{
							var max = 0;
							var sorter;
							for(sorter =0;sorter<globalindex;sorter++)
							{
								if (max < parseFloat(FinalArray[FinalArtistArray[sorter][0]]))
								{
									max = parseFloat(FinalArray[FinalArtistArray[sorter][0]]);
								}
							}
							
						}
						catch(e)
						{
							document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.1";

						}
						//</Sorting>
						
						document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|501.7";
						var s;
						var objRegExp = /&(\w+);/;
						
						
						if(globalindex == 0)
						{
							document.write("Nothing! <br>");
							document.write("This maybe due to one of the following reasons: <br>");
							document.write("1) Insufficient music likes and interests on facebook. Please like your favourite music and artists on facebook. <br>");
							document.write("2) One of the sites <a href=\"http://www.youtube.com/\">Youtube</a>, <a href=\"https://www.facebook.com/\">facebook</a> or <a href=\"http://www.last.fm\">last.fm</a> is blocked on your connection <br>")
							document.write("3) Our recommendation engine might be down.");
						}
						
						
						try
						{
							for(s=0;s<globalindex;s++)
							{
								//document.write(FinalArtistArray[s] +">>>>" + FinalArray[FinalArtistArray[s][0]] +"<br>");
								//document.write(parseFloat(FinalArray[FinalArtistArray[s][0]]) + ">" + max +"<br>");
								//
								try
								{
									if(parseFloat(FinalArray[FinalArtistArray[s][0]]) > max*0.2)
									{
										var searchquery = FinalArtistArray[s][0].replace(objRegExp,"");
										var searchqueryparts = searchquery.split(" ");
										var finalindex = 0;
										var finalsearchquery = "";
										for(finalindex=0;finalindex<searchqueryparts.length;finalindex++)
										{
											finalsearchquery = finalsearchquery + "/" + searchqueryparts[finalindex];
										}
										document.write("<li><a href="+"artist.html?id="+finalsearchquery+" target=\"_newtab\">"+FinalArtistArray[s][0]+"</a>"+"</li>");
									}
								}
								catch(e)
								{
									document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.1";
								}
							}
						}
						catch(e)
						{
							document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|.2";
							document.write("Error Occurred while Fetching Data. Plz report this bug.<br> To report this bug select all text and mail to <a href=\"mailto:rmm.iiitd@gmail.com\">Recomend Me Music rmm.iiitd@gmail.com</a></p>");
						}
						
						document.getElementById('codefordev').innerHTML = document.getElementById('codefordev').innerHTML + "|501.7";
												
						</script>
					</p>
					&nbsp;</div>
			</div>
			<div class="separator"></div>
			<div class="wrap">
				<div class="oneOfThree first">
				</div>
				<div class="oneOfThree">
				</div>
			</div>
		</div>
	</div>
	<div id="footer">
		<div class="container">
			<div class="wrap">
				<div class="footer_logo">
					<a href="start.html" title="Recommend Me Music">Recommend Me Music</a>
				</div>
				<ul id="footer_nav">
					<li class="current"><a href="start.html">Home</a></li>
					<li><a href="team.html">TEAM</a></li>
					<li><a href="privacy.html">PRIVACY</a></li>
					<li><a href="reportabug.html">REPORT A BUG</a></li>
				</ul>
			</div>
		</div>
		<div class="clear"></div>
	</div>
</body> 
</html>